home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
COMMUNIC
/
TERMINAL
/
1589.ZIP
/
TERMIO.C
< prev
next >
Wrap
Text File
|
1989-04-13
|
13KB
|
436 lines
#include "windows.h"
#include <stdio.h>
#include <fcntl.h>
#include <stdarg.h>
#include "icu_user.h"
#include "term.h"
#include "termdefs.h"
/**/
/*doc************************************************************************
*
* NAME
*
* ReadLine() - read a line from the port buffer
*
* FORMAT
*
* ReadLine()
*
* DESCRIPTION
* This function read the next line of data from the input queue. It
* will read until the port is empty or it has read 240 characters.
* This line will get put into the 'next_line' field. If it exceeds the
* width of the screen, the 'next_line' variable will be incremented
* and so on.
*
* There is special character handling in this function to allow
* special characters and escape sequences to be handled.
*
* RETURN VALUE
* TRUE - error reading data
* FALSE - no error
*
* MODIFIES
* next_line
* top_line
*
* REFERENCES
*
*end************************************************************************/
ReadLine( )
{
/****************************************
* local variable declarations *
****************************************/
char port_char; /* character read from port */
int chars_read; /* number of characters read */
int read_stat;
/****************************************
* start of function code *
****************************************/
chars_read = 240;
read_stat = 1;
TermShowCaret( FALSE ); /* Hide the caret */
do {
read_stat = ReadComm(nCID,(LPSTR)&port_char,1);/* Read the next character */
if ( read_stat < 1 )
break; /* Input buffer empty */
if ( Capture == TRUE )
CaptureLog( port_char ); /* Log every character read */
if (port_char == 127) { /* Destructive backspace */
if (curs_pos.x > char_w)
curs_pos.x -= char_w;
if (next_char > 0)
next_char--;
display[next_line].string[next_char] = ' ';
*buff = ' ';
TextOut(hTermDC,curs_pos.x,curs_pos.y,(LPSTR) buff, 1); /* Erase char */
}
else if (port_char == ESC) /* An ESCAPE sequence is starting */
ProcessEscape( );
else if (port_char < 0x20) /* A CONTROL character was sent */
ProcessCtrl(port_char);
else { /* if NORMAL character, put on screen */
if ( GraphicsMode )
port_char = TranslateGraphic( port_char );
TextOut( hTermDC, curs_pos.x, curs_pos.y, (LPSTR) &port_char, 1 );
display[next_line].string[next_char] = port_char;
UpdateCursPos(NEXT_CHAR); /* Move cursor to next character */
} /* End if normal character */
} while ( --chars_read ); /* Go until EOL or read 80 chars */
OUT:
TermShowCaret( TRUE ); /* Display the caret */
return(FALSE);
}
/**/
/*doc************************************************************************
*
* NAME
*
* UpdateCursPos() - update cursor position on screen
*
* FORMAT
*
* UpdateCursPos(how)
* int how - how to update position (NEXT_LINE, NEXT_CHAR or DOWN_LINE)
*
* DESCRIPTION
* This function will advance the cursor. How it is advanced depends on
* the 'how' flag. If it is NEXT_LINE, the cursor will be moved to the
* start of the next line, and the screen will be scrolled if necessary.
* If it is NEXT_CHAR, the cursor will be moved over once to the right
* unless at the edge of the screen, when it will be moved to the next
* line. The cursor will be moved down one line if how is DOWN_LINE.
*
* RETURN VALUE
*
* MODIFIES
* curs_pos
*
* REFERENCES
*
*end************************************************************************/
UpdateCursPos(how)
int how;
{
/****************************************
* local variable declarations *
****************************************/
int i;
char *hold;
/****************************************
* if cursor is at edge of screen, move *
* it to the next line *
****************************************/
if ((how == NEXT_CHAR)&&((curs_pos.x/char_w)>=no_cols||next_char>=no_cols))
how = NEXT_LINE;
/****************************************
* handle moving the cursor to the next *
* character position *
****************************************/
if (how == NEXT_CHAR) {
curs_pos.x += char_w;
next_char++;
}
/****************************************
* handle moving the cursor to the next *
* line and scrolling the screen *
****************************************/
else { /* NEXT_LINE or DOWN_LINE */
if ( how != DOWN_LINE ) {
curs_pos.x = char_w; /* will start on new line */
next_char = 0;
} /* Is screen full??? */
if ( next_line >= no_lines || curs_pos.y/char_h >= no_lines) {
hold = display[0].string; /* Scroll display memory */
for( i = 0; i < (no_lines-1); i++ )
display[i].string = display[i+1].string;
memset( hold, ' ', no_cols );
display[no_lines-1].string = hold;
next_line = no_lines - 1;
PaintWindow = FALSE;
ScrollWindow(hWndTerm,0,0 - char_h,NULL,NULL); /* Scroll whole window */
UpdateWindow(hWndTerm);
}
else { /* if screen isn't full */
curs_pos.y += char_h;
next_line++;
}
}
return(FALSE);
}
/**/
/*doc************************************************************************
*
* NAME
*
* TranslateKey() - translate certain keys into control sequences
*
* FORMAT
*
* TranslateKey(key)
* int key - windows name for the key to be translated
*
* DESCRIPTION
* This function translates the key passed to it into a sequence of
* control and ascii characters. It sends those characters to the
* computer. If the key passed to it is not one processed here, it
* returns a FALSE, if it is processed, it returns a TRUE.
*
* RETURN VALUE
* TRUE - key processed
* FALSE - key not processed
*
* MODIFIES
*
* REFERENCES
* TransmitCommChar()
*
*end************************************************************************/
TranslateKey(key)
int key;
{
/****************************************
* local variable declarations *
****************************************/
int i, ret, sendindex ;
sendindex = -1;
switch (key) {
case VK_F1: /* an F1 function key was pressed */
if ( HIWORD(GetKeyState(VK_SHIFT)) )
sendindex = FUNCTION11;
else
sendindex = FUNCTION1;
break;
case VK_F2: /* an F2 function key was pressed */
if ( HIWORD(GetKeyState(VK_SHIFT)) )
sendindex = FUNCTION12;
else
sendindex = FUNCTION2;
break;
case VK_F3: /* an F3 function key was pressed */
if ( HIWORD(GetKeyState(VK_SHIFT)) )
sendindex = FUNCTION13;
else
sendindex = FUNCTION3;
break;
case VK_F4: /* an F4 function key was pressed */
if ( HIWORD(GetKeyState(VK_SHIFT)) )
sendindex = FUNCTION14;
else
sendindex = FUNCTION4;
break;
case VK_F5: /* an F5 function key was pressed */
if ( HIWORD(GetKeyState(VK_SHIFT)) )
sendindex = FUNCTION15;
else
sendindex = FUNCTION5;
break;
case VK_F6: /* an F6 function key was pressed */
if ( HIWORD(GetKeyState(VK_SHIFT)) )
sendindex = FUNCTION16;
else
sendindex = FUNCTION6;
break;
case VK_F7: /* an F7 function key was pressed */
sendindex = FUNCTION7;
break;
case VK_F8: /* an F8 function key was pressed */
sendindex = FUNCTION8;
break;
case VK_F9: /* an F9 function key was pressed */
sendindex = FUNCTION9;
break;
case VK_F10: /* an F10 function key was pressed */
sendindex = FUNCTION0;
break;
case VK_F11:
sendindex = FUNCTION11;
break;
case VK_F12:
sendindex = FUNCTION12;
break;
case VK_F13:
sendindex = FUNCTION13;
break;
case VK_F14:
sendindex = FUNCTION14;
break;
case VK_F15:
sendindex = FUNCTION15;
break;
case VK_F16:
sendindex = FUNCTION16;
break;
case VK_LEFT: /* left arrow key */
sendindex = LEFTARROW;
break;
case VK_UP: /* up arrow key */
sendindex = UPARROW;
break;
case VK_RIGHT: /* right arrow key */
sendindex = RIGHTARROW;
break;
case VK_DOWN: /* down arrow key */
sendindex = DOWNARROW;
break;
default:
return (FALSE); /* this key wasn't processed */
break;
}
if ( sendindex != -1 ) { /* Send character sequence */
for ( i = 0; emulate[i].meaning != sendindex && emulate[i].meaning; i++ );
ret = strlen( emulate[i].sequence );
if ( ret > 0 )
ret = WriteComm( nCID, (LPSTR) emulate[i].sequence, ret );
}
return(TRUE); /* the key was processed */
}
/****************************************************************************/
/****************************************************************************/
OpenCapture()
{
if ( CaptureFD > 0 )
return( 0 );
LoadString( hInstTerm, IDSCAPTURE, (PSTR) buff, 30 );
CaptureFD = open( buff, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0000200 );
if ( CaptureFD < 1 )
return( -1 );
return( TRUE );
}
/****************************************************************************/
/****************************************************************************/
CloseCapture()
{
Capturelog( (char) -1 ); /* Flush the log file */
close( CaptureFD );
}
/****************************************************************************/
/****************************************************************************/
CaptureLog( port_char )
char port_char;
{
int ret;
static int cnt = 0;
if ( port_char == (char) -1 || port_char == 0x0A || cnt > 65 ) {
if ( port_char != 0x0A )
CaptureBuff[cnt++] = port_char;
CaptureBuff[cnt++] = ']';
CaptureBuff[cnt++] = '\n';
CaptureBuff[cnt] = '\0';
ret = write( CaptureFD, CaptureBuff, cnt );
memset( CaptureBuff, '\0', 80 );
sprintf( CaptureBuff, "%4d [", CaptureLine++ );
cnt = 0;
}
else
CaptureBuff[cnt++] = port_char;
}
/****************************************************************************/
/****************************************************************************/
TranslateGraphic( GraphicNumber )
char GraphicNumber;
{
char Graphic;
switch( GraphicNumber ) {
case '0':
Graphic = 194; /* ┬ */
break;
case '1':
Graphic = 192; /* └ */
break;
case '2':
Graphic = 218; /* ┌ */
break;
case '3':
Graphic = 191; /* ┐ */
break;
case '4':
Graphic = 195; /* ├ */
break;
case '5':
Graphic = 217; /* ┘ */
break;
case '6':
Graphic = 179; /* │ */
break;
case '7':
Graphic = 178; /* ▓ */
break;
case '8':
Graphic = 197; /* ┼ */
break;
case '9':
Graphic = 180; /* ┤ */
break;
case ':':
Graphic = 196; /* ─ */
break;
case ';':
Graphic = 177; /* ▒ */
break;
case '<':
Graphic = 205; /* ═ */
break;
case '=':
Graphic = 193; /* ┴ */
break;
case '>':
Graphic = 186; /* ║ */
break;
case '?':
Graphic = 176; /* ░ */
break;
default:
Graphic = GraphicNumber;
break;
}
return( Graphic );
}
/****************************************************************************/
/****************************************************************************/
Beep()
{
MessageBeep( 1 );
}
/****************************************************************************/
/****************************************************************************/
TermShowCaret( mode )
int mode ;
{
if ( TermHasFocus && mode && CaretMode ) {
SetCaretPos( curs_pos.x, curs_pos.y );
ShowCaret( hWndTerm );
}
else if ( TermHasFocus )
HideCaret( hWndTerm );
}